<?php
/**
 * 微信类
 */
namespace app\index\model;

use think\Log;

class weixin
{
	//微信基本属性
	protected $appid = 'wx7b93bcf5758bde90';
	protected $AppSecret = '4b9c78e41130b35a621c0dffa0a29c63';
	protected $token = 'zhoupengfei1992';
	protected $EncodingAESKey = 'xYtaumja0UIsj5HOQMBEuosfnOHXqkmAqZE1DjtTjPq';

	//验证消息数据
	protected $signature;
	protected $timestamp;
	protected $nonce;
	protected $echostr;

	/**
	 * 初始化
	 * @return boolean 成功/失败
	 */
	public function __construct($signature ,$timestamp ,$nonce ,$echostr){
		$this->signature = $signature;
		$this->timestamp = $timestamp;
		$this->nonce = $nonce;
		$this->echostr = $echostr;
		$this->getsha1();
	}
	
	/**
	 * 加密验证
	 * @return boolean 成功/失败
	 */
	protected function getsha1(){
		$tmparr = array($this->token, $this->timestamp, $this->nonce);
		Log::record(serialize($tmparr));
		sort($tmparr, SORT_STRING);
		$tmpstr = implode($tmparr);
		$tmpstr = sha1($tmpstr);
		if ($tmpstr == $this->signature) {
            echo $this->echostr;
			Log::record('微信接入成功');
        }else{
        	echo 'false';
			Log::record('微信接入失败');
        }
		Log::save();
	}
}